package com.zycfc.zsf.boot.util.machine;

import com.zycfc.zsf.boot.util.text.*;
import java.net.*;
import org.slf4j.*;

public class MachineUtil
{
    private static final Logger log;
    private static String hostName;
    private static String hostIp;
    
    public static void init() {
        if (StringUtils.isEmpty(MachineUtil.hostIp)) {
            synchronized (MachineUtil.class) {
                if (StringUtils.isEmpty(MachineUtil.hostIp)) {
                    try {
                        final InetAddress address = InetAddress.getLocalHost();
                        MachineUtil.hostName = address.getHostName();
                        MachineUtil.hostIp = address.getHostAddress();
                    }
                    catch (UnknownHostException e) {
                        MachineUtil.log.error("MachineUtil \u521d\u59cb\u5316\u83b7\u53d6hostName/hostIp Exception:{}", (Throwable)e);
                    }
                }
            }
        }
    }
    
    public static String getHostName() {
        if (StringUtils.isEmpty(MachineUtil.hostName)) {
            init();
        }
        return MachineUtil.hostName;
    }
    
    public static String getHostIp() {
        if (StringUtils.isEmpty(MachineUtil.hostIp)) {
            init();
        }
        return MachineUtil.hostIp;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)MachineUtil.class);
        MachineUtil.hostName = null;
        MachineUtil.hostIp = null;
        init();
    }
}
